package itheima.dame;

import java.lang.reflect.Method;

public class AnnotationTest3 {
    public static void main(String[] args) {
        // 获取 Demo 类
        Class<?> demoClass = Demo.class;

        // 解析类上的注解
        if (demoClass.isAnnotationPresent(MyTest4.class)) {
            MyTest4 myTest4 = demoClass.getAnnotation(MyTest4.class);
            parseMyTest4(myTest4, "Class");
        }

        // 解析方法上的注解
        Method[] methods = demoClass.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(MyTest4.class)) {
                MyTest4 myTest4 = method.getAnnotation(MyTest4.class);
                parseMyTest4(myTest4, method.getName());
            }
        }
    }

    private static void parseMyTest4(MyTest4 myTest4, String location) {
        System.out.println(location + " - value: " + myTest4.value());
        System.out.println(location + " - aaa: " + myTest4.aaa());
        System.out.println(location + " - bbb: " + String.join(", ", myTest4.bbb()));
    }

}
